home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 003 / riscscript / !RiScript / System / ErrHandler next >
Text File  |  1994-01-16  |  3KB  |  96 lines

  1. %!
  2. serverdict begin 0 exitserver
  3.  
  4. %  Article 4903 of comp.lang.postscript:
  5. %  From: lhamey@mqccsunb.mqcc.mq.oz.au (Len Hamey)
  6. %  Newsgroups: comp.lang.postscript
  7. %  Subject: PostScript Error Dump Routine (free)
  8. %  Keywords: handleerror
  9. %  Message-ID: <432@macuni.mqcc.mq.oz>
  10. %  Date: 27 Aug 90 04:31:59 GMT
  11. %  Sender: news@macuni.mqcc.mq.oz
  12. %  Organization: Macquarie University, Sydney
  13. %  Lines: 74
  14.  
  15. % Whilst trying to determine why a particular PS file would not print,
  16. % I developed the following error trap routine.  I offer it to the net
  17. % freely (you get what you pay for, usually).  I would be interested
  18. % in better/improved solutions to the same problem.
  19.  
  20. % Catch PS error and print out potentially useful info.
  21. % If your PS code fails, just include this at start. Upon failure
  22. % it dumps the current (incomplete) page then prints out two pages
  23. % of error info.
  24.  
  25. % RvdB: Check for interactive input added -- 16/01/94
  26.  
  27. /ErrorStringBuffer 1000 string def
  28. errordict /handleerror
  29. { showpage
  30. % showpage also initializes graphics state.
  31.   /Times-Roman findfont 12 scalefont setfont
  32.   {
  33.     72 680 moveto
  34.     (Error encountered: ) show
  35.     $error /errorname get ErrorStringBuffer cvs show
  36.     72 660 moveto (Command in error: ) show
  37.     $error /command get ErrorStringBuffer cvs show
  38.     72 640 moveto
  39.     vmstatus (Virtual memory:  max: ) show ErrorStringBuffer cvs show
  40.       (   used: ) show ErrorStringBuffer cvs show
  41.       (   level: ) show ErrorStringBuffer cvs show
  42.     72 600 moveto
  43.     (Context:) show
  44.     (\%stdin) (r) file bytesavailable 0 gt % non-interactive input only [RB]
  45.     { 1 1 5
  46.       { pop currentpoint 16 sub exch pop 108 exch moveto
  47.         (\%stdin) (r) file ErrorStringBuffer readline exch show
  48.         % Status_of_readline_false_if_end_of_file
  49.         not { exit } if
  50.       } for
  51.     } if 
  52.     currentpoint 20 sub exch pop 72 exch moveto
  53.     (Execution Stack:) show
  54.     $error /estack get
  55.       length 1 sub  % n-1
  56.       dup 100 sub dup % n-1 n-101 n-101
  57.       0 lt % n-1 n-101 n-101<0
  58.       { 0 } { dup } ifelse % n-1 n-101 max(0,n-101)
  59.       exch pop -1 exch % n-1 -1 max(0,n-101)
  60.       { currentpoint 16 sub exch pop 108 exch moveto
  61.         $error /estack get exch get ErrorStringBuffer cvs show
  62.       } for
  63.   } stopped pop
  64.   showpage
  65.   {
  66.     72 680 moveto
  67.     (Operand Stack:) show
  68.     $error /ostack get
  69.       length 1 sub  % n-1
  70.       dup 100 sub dup % n-1 n-101 n-101
  71.       0 lt % n-1 n-101 n-101<0
  72.       { 0 } { dup } ifelse % n-1 n-101 max(0,n-101)
  73.       exch pop -1 exch % n-1 -1 max(0,n-101)
  74.       { currentpoint 16 sub exch pop 108 exch moveto
  75.         $error /ostack get exch get % Item from operand stack
  76.         dup type ErrorStringBuffer cvs show (: ) show
  77.         ErrorStringBuffer cvs show
  78.       } for
  79.   } stopped pop
  80.   showpage
  81. } bind put
  82.  
  83. % The following is a test example of an error...
  84. % 4 5 6 [1 2 3] (Fred was here) notandexistingoperator morebadstuff
  85. % This is a line of text
  86. % There is a little more
  87. %% A comment line
  88. % There follows more
  89. % and more
  90.  
  91.  
  92. %                       Len Hamey
  93. %                       Macquarie University
  94.  
  95.  
  96.